# coding:utf-8
# @Time    : 2021/11/29 17:38
# @Author  : Martin
from page_object.base.base_page import BasePage
from page_object.base.page_items_coupon import PageItemsCoupon
from util.read_file import get_approve_data


class OfflineNonCoupon(BasePage):
    _base_url = "/nspas-web-in/judgeComType.do?activityType=NOSHOPCOUPONACTIVITY"

    def select_company(self, txt):
        """
        选则公司类型
        :param txt: 公司类型
        :return:
        """
        self.select('id', 'comType', txt)
        self.click('link text', '确定')

        return OfflineNonCouponCreate(self.driver, self.logger, txt)


class OfflineNonCouponCreate(PageItemsCoupon):
    def __new__(cls, *args, **kwargs):

        instance = super().__new__(cls)
        instance._base_url = f"/nspas-web-in/processRoleFilter.do?businessTemplateId={args[2]}&comType=1"
        return instance

    def __init__(self,driver, logger,template):
        super().__init__(driver, logger)

    def check_show_area(self, area_ids):
        """
        勾选展示区域
        :param area_ids:
        """
        for area in area_ids:
            self.single_checked('xpath', f'//input[@value="{area}"][@name="offLine_showArea"]')

    def input_act_count(self, txt=None):
        """
        活动总次数
        :param txt:
        :return:
        """
        if txt:
            self.input('name', 'type1_activityTotal', txt)

    @staticmethod
    def get_approve_head_create():
        """
        获取总部新建审批流账号数据
        :return:
        """
        return get_approve_data('offline_noshop_coupon', 'area', 'create')

    def check_channel(self, channel_ids):
        """
        勾选终端
        :param channel_ids:
        :return:
        """
        channel_ids = str(channel_ids).split(',')
        for channel in channel_ids:

            self.single_checked('xpath',
                                f'//input[@value="{channel}"][@name="promotionMaster.activityAccessPointCode"]')
            if channel == '37':
                self.switch_alert()

    def check_rule_channel(self, channel_ids):
        """
        勾选用券终端
        :param channel_ids:
        :return:
        """
        channel_ids = str(channel_ids).split(',')
        for channel in channel_ids:
            self.single_checked('xpath',
                                f'//input[@value="{channel}"][@name="ticketRule.ticketPosCode"]')
            if channel == '37':
                self.switch_alert()


if __name__ == '__main__':
    pass
